import 'package:flutter/material.dart';

class MyTextField extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => MyTextFieldState();
}

class MyTextFieldState extends State {
  var _username = new TextEditingController();

  @override
  void initState() {
    super.initState();
    _username.text = '初始值';
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text('MyTextField')),
        body: Padding(
            padding: EdgeInsets.all(20),
            child: ListView(
              children: [
                TextField(
                  decoration: InputDecoration(
                    border: OutlineInputBorder(),
                  ),
                  controller: _username,
                ),
                SizedBox(height: 10),
                Container(
                    width: double.infinity,
                    height: 40,
                    child: RaisedButton(
                      child: Text('登录'),
                      color: Colors.blue,
                      textColor: Colors.white,
                      onPressed: () {
                        print('登录 --- ${this._username.text}');
                      },
                    )),
                SizedBox(height: 50),
                TextField(
                    decoration: InputDecoration(
                  hintText: '请输入搜索内容',
                  border: OutlineInputBorder(),
                )),
                SizedBox(height: 20),
                TextField(
                    maxLines: 4,
                    decoration: InputDecoration(
                      hintText: '请输入搜索内容',
                      border: OutlineInputBorder(),
                    )),
                SizedBox(height: 20),
                TextField(
                    obscureText: true,
                    decoration: InputDecoration(
                      hintText: '请输入搜索内容',
                      border: OutlineInputBorder(),
                    )),
                SizedBox(height: 20),
                TextField(
                    decoration: InputDecoration(
                  border: OutlineInputBorder(),
                  labelText: '用户名',
                )),
                SizedBox(height: 20),
                TextField(
                    decoration: InputDecoration(
                  border: OutlineInputBorder(),
                  labelText: '用户名',
                  icon: Icon(Icons.people),
                )),
                SizedBox(height: 20),
                TextField(
                    controller: _username,
                    decoration: InputDecoration(
                      border: OutlineInputBorder(),
                    )),
              ],
            )));
  }
}
